﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

using NantAssistant.EventArgs;
using NantAssistant.Util;

namespace NantAssistant
{
    /// <summary>
    /// Interaction logic for TargetView.xaml
    /// </summary>
    public partial class TargetView : UserControl
    {
        public EventHandler<TargetSelectionChangedEventArgs> SelectionChanged;
        private Target nantTarget;

        public bool IsHighlighted { get; private set; }
        public int Position { get; private set; }

        public TargetView(int pos, Target target)
        {            
            InitializeComponent();

            nantTarget = target;
            Position = pos;
            txtTargetDescription.Text = string.Format("{0}.\t{1}", pos, target.Description);
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            if (SelectionChanged != null)
                SelectionChanged(this, new TargetSelectionChangedEventArgs(nantTarget));
        }

        public void ChangeCheck()
        {
            chkSelect.IsChecked = !chkSelect.IsChecked;
        }

        private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
        {
            ChangeCheck();
        }

        public void ToggleHighlight()
        {
            Thickness newThickness;
            Brush newBrush;

            if (IsHighlighted)
            {
                newThickness = new Thickness(0, 1, 0, 1);
                newBrush = Brushes.Gray;
            }
            else
            {
                newThickness = new Thickness(3,1,3,1);
                newBrush = Brushes.CornflowerBlue;
            }

            IsHighlighted = !IsHighlighted;
            TargetBorder.BorderBrush = newBrush;
            TargetBorder.BorderThickness = newThickness;
        }
    }
}
